package com.selenium.testclass;

import java.util.List;
import java.util.Map;

import net.htmlparser.jericho.Element;
import net.htmlparser.jericho.HTMLElementName;
import net.htmlparser.jericho.Source;

import org.testng.Reporter;

import com.selenium.core.SelTestCase;
import com.selenium.core.functionlibrary.HTMLTableParser;

public class WebTest extends SelTestCase {
	
	public void testHTMLParser() {
		
		// Get Source object for HTML Tables.
		Source source = new Source(selenium.getHtmlSource());
		List<Element> table = source.getAllElements(HTMLElementName.TABLE);

		Reporter.log("Number of Tables are: " +table.size());

		// Retrieve table data from a specific table.
		Source tableSource = new Source(table.get(3));
				
		Reporter.log("Table data is:" +HTMLTableParser.getTableData(tableSource, false));
					
		Reporter.log("True Table data is:" +HTMLTableParser.getTableData(tableSource, true));
		
		// Count number of rows in table		
		Reporter.log("Number of Rows are: " +HTMLTableParser.countTableRows(tableSource));
		
		// List number of columns in individual rows
		Map<Integer, Integer> rowAndCoumnCount = HTMLTableParser.countTableColumnsInRows(tableSource);		
		for(Map.Entry<Integer, Integer> rowAndColumnData : rowAndCoumnCount.entrySet()){
			Reporter.log("Number of columns at row: " +rowAndColumnData.getKey()
					+" are: " +rowAndColumnData.getValue());
		}		
		// Get data from individual columns.
		System.out.println("Column specific table data is:" +HTMLTableParser.getTableDataForColumn(tableSource, false, 0, 1));
		System.out.println("Column specific raw table data is:" +HTMLTableParser.getTableDataForColumn(tableSource, true, 0, 1));
		Reporter.log("Column specific table data is:" +HTMLTableParser.getTableDataForColumn(tableSource, false, 0, 1));
		Reporter.log("Column specific raw table data is:" +HTMLTableParser.getTableDataForColumn(tableSource, true, 0, 1));
	}
} 
